﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WS.EKA.Model;
using WS.EKA.Core.DI;
using WS.EKA.ServiceInterface;
using AttributeRouting.Web.Http;
using WS.EKA.Utilities.Consts;
using WS.EKA.Portal.Filters;

namespace WS.EKA.Portal.Controllers
{
    [AuthencationFilter(true)]
    public class MemberMessageController : ControllerBase
    {
        private IMemberMessage memberMessage;

        public MemberMessageController(IMemberMessage memberMessage)
        {
            this.memberMessage = memberMessage;
        }
        // GET api/membermessage/list/{pageIndex}
        [GET("api/membermessage/list/{pageIndex}")]
        public Dictionary<string, object> Get(int pageIndex)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
           
            int recordTotal=0;
            List<MemberMessage> list = memberMessage.Get(GetCurrentUser(), pageIndex, out recordTotal);
            dic.Add(PagerConst.Count, recordTotal);
            dic.Add(PagerConst.Data, list);
            return dic;
        }
        // PUT api/membermessage/5
        public HttpStatusCode Put(Guid id)
        {
            int result = memberMessage.IsReaded(id, GetCurrentUser());
            if (result>0)
            {
                return HttpStatusCode.Accepted;
            }
            return HttpStatusCode.InternalServerError;
        }

        [DELETE("api/membermessage/delete/{msgId}")]
        public HttpStatusCode Delete(Guid msgId)
        {
            int result = memberMessage.Delete(msgId, GetCurrentUser());
            if (result > 0)
            {
                return HttpStatusCode.Accepted;
            }
            return HttpStatusCode.InternalServerError;
        }
    }
}
